package com.sunyard.client2.ui;

import javax.swing.JPanel;
import javax.swing.JButton;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

import javax.swing.JLabel;
import javax.swing.SwingConstants;
import javax.swing.JTextField;

import com.sunyard.client.SunEcmClientApi;
import com.sunyard.client.bean.ClientBatchBean;
import com.sunyard.client2.ConnectionFactory;
import com.sunyard.client2.conf.ConfUtil;
import com.sunyard.ecm.server.bean.MigrateBatchBean;
import com.sunyard.util.DateUtil;

public class Query extends JPanel {
	private JTextField textField;
	private JTextField textField_1;
	private JTextField textField_2;
	private JTextField textField_3;
	private JTextField textField_4;

	/**
	 * Create the panel.
	 */
	public Query() {
		setLayout(null);

		JButton btnNewButton = new JButton("查询");
		btnNewButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				try {
					ClientBatchBean clientBatchBean = new ClientBatchBean();
					clientBatchBean.setModelCode(textField.getText());
					clientBatchBean.setUser(ConfUtil.getString("userName", ""));
					clientBatchBean.setPassWord(ConfUtil.getString("passWord", ""));
					clientBatchBean.setDownLoad(true);
					clientBatchBean.getIndex_Object().setContentID(textField_1.getText());
					clientBatchBean.getIndex_Object().setVersion(textField_4.getText());
					clientBatchBean.getIndex_Object().addCustomMap(textField_2.getText(), textField_3.getText());
					clientBatchBean.setToken_code(ConfUtil.getString("token_value", ""));
					SunEcmClientApi clientApi = ConnectionFactory.getConnection();
					String resultMsg = clientApi.queryBatch(clientBatchBean, ConfUtil.getString("groupName", ""));
					ResultMessageBox.getInstance().showMessage(resultMsg);
				} catch (Exception e1) {
					ResultMessageBox.getInstance().showMessage(e1.getMessage());
				}
			}
		});
		btnNewButton.setBounds(98, 304, 93, 23);
		add(btnNewButton);

		JButton btnNewButton_1 = new JButton("删除");
		btnNewButton_1.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				try {
					ClientBatchBean clientBatchBean = new ClientBatchBean();
					clientBatchBean.setModelCode(textField.getText());
					clientBatchBean.setUser(ConfUtil.getString("userName", ""));
					clientBatchBean.setPassWord(ConfUtil.getString("passWord", ""));
					clientBatchBean.getIndex_Object().setContentID(textField_1.getText());
					clientBatchBean.getIndex_Object().addCustomMap(textField_2.getText(), textField_3.getText());
					clientBatchBean.setToken_code(ConfUtil.getString("token_value", ""));
					SunEcmClientApi clientApi = ConnectionFactory.getConnection();
					String resultMsg = clientApi.delete(clientBatchBean, ConfUtil.getString("groupName", ""));
					ResultMessageBox.getInstance().showMessage(resultMsg);
				} catch (Exception e1) {
					ResultMessageBox.getInstance().showMessage(e1.getMessage());
				}
			}
		});
		btnNewButton_1.setBounds(270, 304, 93, 23);
		add(btnNewButton_1);

		JButton btnNewButton_2 = new JButton("立即迁移");
		btnNewButton_2.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {

				MigrateBatchBean m = new MigrateBatchBean();
				m.setMigrate(true);
				m.setModelCode(textField.getText());
				m.setUser(ConfUtil.getString("userName", ""));
				m.setPassWord(ConfUtil.getString("passWord", ""));
				m.getIndex_Object().setContentID(textField_1.getText());
				m.getIndex_Object().addCustomMap(textField_2.getText(), textField_3.getText());
				m.setToken_code(ConfUtil.getString("token_value", ""));
				try {
					SunEcmClientApi clientApi = ConnectionFactory.getConnection();
					String resultMsg = clientApi.immedMigrate(m, ConfUtil.getString("groupName", ""));
					ResultMessageBox.getInstance().showMessage(resultMsg);
				} catch (Exception e1) {
					ResultMessageBox.getInstance().showMessage(e1.getMessage());
				}
			
			}
		});
		btnNewButton_2.setBounds(417, 304, 117, 23);
		add(btnNewButton_2);

		JLabel label = new JLabel("模型：");
		label.setHorizontalAlignment(SwingConstants.RIGHT);
		label.setBounds(75, 45, 76, 15);
		add(label);

		textField = new JTextField();
		textField.setText(ConfUtil.getString("modelCode", ""));
		textField.setColumns(10);
		textField.setBounds(161, 42, 389, 21);
		add(textField);

		JLabel label_1 = new JLabel("批次编号：");
		label_1.setHorizontalAlignment(SwingConstants.RIGHT);
		label_1.setBounds(75, 89, 76, 15);
		add(label_1);

		textField_1 = new JTextField();
		textField_1.setColumns(10);
		textField_1.setBounds(161, 86, 389, 21);
		add(textField_1);

		JLabel label_2 = new JLabel("时间字段：");
		label_2.setHorizontalAlignment(SwingConstants.RIGHT);
		label_2.setBounds(75, 134, 76, 15);
		add(label_2);

		textField_2 = new JTextField();
		textField_2.setText(ConfUtil.getString("STARTCOLUMN", ""));
		textField_2.setColumns(10);
		textField_2.setBounds(161, 131, 140, 21);
		add(textField_2);

		JLabel label_3 = new JLabel("业务时间：");
		label_3.setHorizontalAlignment(SwingConstants.RIGHT);
		label_3.setBounds(324, 134, 76, 15);
		add(label_3);

		textField_3 = new JTextField();
		textField_3.setText(ConfUtil.getString("STARTDATE", DateUtil.get8bitDateStr()));
		textField_3.setColumns(10);
		textField_3.setBounds(410, 131, 140, 21);
		add(textField_3);
		
		JLabel lblNewLabel = new JLabel("版本：");
		lblNewLabel.setHorizontalAlignment(SwingConstants.RIGHT);
		lblNewLabel.setBounds(75, 178, 76, 15);
		add(lblNewLabel);
		
		textField_4 = new JTextField();
		textField_4.setText("0");
		textField_4.setColumns(10);
		textField_4.setBounds(161, 175, 140, 21);
		add(textField_4);

	}
}
